home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / c.lqr / TANH.C < prev    next >
Text File  |  1985-06-03  |  1KB  |  44 lines

  1.  
  2. /***********************************************************
  3.  *               The TULSA IBM C BOARD                     *
  4.  *                   918-664-8737                          *
  5.  *             300/1200 XMODEM, 24 Hours                   *
  6.  **********************************************************/
  7.  
  8. #include "math.h"
  9.  
  10. #define P0 -0.16134119023996228053e+4
  11. #define P1 -0.99225929672236083313e+2
  12. #define P2 -0.96437492777225469787e+0
  13. #define Q0 +0.48402357071988688686e+4
  14. #define Q1 +0.22337720718962312926e+4
  15. #define Q2 +0.11274474380534949335e+3
  16.  
  17. #define gP(g) (((P2*g P1)*g P0)*g)
  18. #define Q(g) (((g Q2)*g Q1)*g Q0)
  19.  
  20. double tanh(x)
  21. double x;
  22. {
  23.         double f,g,r;
  24.  
  25.         f = fabs(x);
  26.         if (f > 25.3)
  27.                 r = 1.0;
  28.         else if (f > 0.54930614433405484570) {
  29.                 r = 0.5 - 1.0/(exp(f+f)+1.0);
  30.                 r += r;
  31.         } else if (f < 2.3e-10)
  32.                 r = f;
  33.         else {
  34.                 g = f*f;
  35.                 r = f + f*
  36.                         (gP(g)
  37.                         /Q(g));
  38.         }
  39.         if (x < 0.0)
  40.                 r = -r;
  41.         return r;
  42. }
  43.  
  44.